<?php

namespace App\Http\model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;


class Set extends Model
{
	/**
	 * [setLinesModel 修改上下线]
	 * @Author   孙丽男
	 * @DateTime 2018-06-11
	 * @param    [type]
	 * @version  6.2
	 */
	public function setLinesModel($id,$is_zx){
		$res = array();
		//查询是否有未结束订单
		$order = Db::table('driver')
			->where([['driver.id',$id],['order.orderstatus',2]])
			->orwhere([['driver.id',$id],['order.orderstatus',3]])
			->join('order_extend','order_extend.driver_id','=','driver.id')
			->join('order','order.extendid','=','order_extend.id')
			->select('order.orderstatus')
			->get();
		$orderArr = json_decode(json_encode($order),true);
		if ($orderArr) {
			
			$res['code'] = 1003;
			return $res;
		}

		$data['is_zx'] = $is_zx;
		$update = Db::table('driver')
			->where('driver.id',$id)
			->update($data);
		if ($update) {

			$fields = array(
				'driver.licenseId',
				'car_car.num'
			);
			$driver = Db::table('driver')
				->where('driver.id',$id)
				->join('car_car','car_car.id','=','driver.car_id')
				->select($fields)
				->first();
			$driverArr = json_decode(json_encode($driver),true);
			$res['code'] = 1000;
			$res['data'] = $driverArr;
			
		}else{
			$res['code'] = 1004;
			
		}
		return $res;
	}
}